<template>
  <div>
    <div class="block">
      <el-timeline>
        <el-timeline-item :timestamp="item.datetimeStarted" v-for="item in eventList" :key="item.communicationEventId"
          icon="el-icon-bell" color="#0bbd87" size="large">
          <div v-html="item.content" @click="handleDetail(item)"></div>
        </el-timeline-item>
      </el-timeline>
    </div>
  </div>
</template>

<script>
import { listEvent, updateEvent } from "@/api/ehr/event";
export default {
  name: "message",
  props: {
    eventList: {
      type: Array,
    },
  },
  data() {
    return {
      colon: false,
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 通信事件类型业务字典
      communicationEventTypeIdOptions: [],
      // 目标当事人业务字典
      partyIdToOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        orderByColumn: "datetimeStarted", // 排序字段
        isAsc: "DESC", // 升序或降序 大写的 ASC或DESC,为空代表升序
        communicationEventTypeId: null,
        statusId: "posted",
        partyIdFrom: null,
        partyIdTo: null,
        datetimeStarted: null,
        datetimeEnded: null,
        subject: null,
        content: null,
        note: null,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.queryParams.partyIdTo = this.$store.state.user.partyId;

    // 通信事件类型业务字典
    this.getEnumDicts("COMM_EVENT_TYPE").then((response) => {
      this.communicationEventTypeIdOptions = response.data;
    });
    // 目标当事人业务字典
    this.getEntityDicts("person:partyId:firstName").then((response) => {
      this.partyIdToOptions = response.data;
    });
  },
  methods: {
    communicationEventTypeIdFormat(row, column) {
      let val = null;
      this.communicationEventTypeIdOptions.forEach((item, index) => {
        if (row.communicationEventTypeId === item.enumCode) {
          val = item.description;
        }
      });
      return val;
    },
    partyIdToFormat(row, column) {
      let val = null;
      this.partyIdToOptions.forEach((item, index) => {
        if (row.partyIdTo === item.partyId) {
          val = item.firstName;
        }
      });
      return val;
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      const communicationEventId = row.communicationEventId;
      console.info("id:" + communicationEventId);
      if (communicationEventId != null) {
        // 设置消息状态为 已读
        row.statusId = "finished";
        updateEvent(row).then((response) => {
          this.$modal.msgSuccess("已阅！");
        });
        this.getList();
      }
    },
    /** 查询消息中心列表 */
    getList() {
      this.loading = true;
      listEvent(this.queryParams).then((response) => {
        this.eventList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
  },
};
</script>
